package payroll.trans;

import payroll.Employee;
import payroll.Paycheck;
import payroll.PayrollDatabase;
import payroll.Transaction;
import java.util.LinkedHashMap;
import java.util.Map;

public class PaydayTransaction implements Transaction {
    private Map<Integer, Paycheck> paychecks = new LinkedHashMap<>();
    @Override
    public void execute() {
        // 为每个雇员支付薪金
        for(Employee e : PayrollDatabase.listAllEmployee()){
            //创建一个Paycheck
            Paycheck paycheck = new Paycheck();
            // 计算工资并填写支付方式到Paycheck
            e.pay(paycheck);  // 根据计算工资的方式，支付方式，填写Paycheck
            //保存Paycheck
            paychecks.put(e.getEmpId(),paycheck);
        }
    }

    public Paycheck getPaycheckOf(int empId) {
        return paychecks.get(empId);
    }
}
